package com.hsnn.medstgmini.trading.pur.model.form;

import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class CreateOrderForm {

	private String recpAddrId; // 地址id
	private Date startTime; // 订单开始时间
	private Date endTime; // 订单结束时间
	private String remark; // 备注
	private String plans; // 购物计划
	private List<PurPlanForm> planList;
	private Integer confirm = 0; // 0:未确认,1:确认
	private Integer isUrgent;//是否紧急

	public String getRecpAddrId() {
		return recpAddrId;
	}

	public void setRecpAddrId(String recpAddrId) {
		this.recpAddrId = recpAddrId;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd")
	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd")
	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getPlans() {
		return plans;
	}

	public void setPlans(String plans) {
		if (StringUtils.isNotBlank(plans)) {
			Gson gson = new Gson();
			Type type = new TypeToken<List<PurPlanForm>>() {
			}.getType();
			planList = gson.fromJson(plans, type);
		}
		this.plans = plans;
	}

	public List<PurPlanForm> getPlanList() {
		return planList;
	}

	public void setPlanList(List<PurPlanForm> planList) {
		this.planList = planList;
	}

	public Integer getConfirm() {
		return confirm;
	}

	public void setConfirm(Integer confirm) {
		this.confirm = confirm;
	}

	public Integer getIsUrgent() {
		return isUrgent;
	}

	public void setIsUrgent(Integer isUrgent) {
		this.isUrgent = isUrgent;
	}

	@Override
	public String toString() {
		return "CreateOrderForm [recpAddrId=" + recpAddrId + ", startTime="
				+ startTime + ", endTime=" + endTime + ", remark=" + remark
				+ ", plans=" + plans + ", planList=" + planList + ", confirm="
				+ confirm + ", isUrgent=" + isUrgent + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((confirm == null) ? 0 : confirm.hashCode());
		result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
		result = prime * result
				+ ((isUrgent == null) ? 0 : isUrgent.hashCode());
		result = prime * result
				+ ((planList == null) ? 0 : planList.hashCode());
		result = prime * result + ((plans == null) ? 0 : plans.hashCode());
		result = prime * result
				+ ((recpAddrId == null) ? 0 : recpAddrId.hashCode());
		result = prime * result + ((remark == null) ? 0 : remark.hashCode());
		result = prime * result
				+ ((startTime == null) ? 0 : startTime.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CreateOrderForm other = (CreateOrderForm) obj;
		if (confirm == null) {
			if (other.confirm != null)
				return false;
		} else if (!confirm.equals(other.confirm))
			return false;
		if (endTime == null) {
			if (other.endTime != null)
				return false;
		} else if (!endTime.equals(other.endTime))
			return false;
		if (isUrgent == null) {
			if (other.isUrgent != null)
				return false;
		} else if (!isUrgent.equals(other.isUrgent))
			return false;
		if (planList == null) {
			if (other.planList != null)
				return false;
		} else if (!planList.equals(other.planList))
			return false;
		if (plans == null) {
			if (other.plans != null)
				return false;
		} else if (!plans.equals(other.plans))
			return false;
		if (recpAddrId == null) {
			if (other.recpAddrId != null)
				return false;
		} else if (!recpAddrId.equals(other.recpAddrId))
			return false;
		if (remark == null) {
			if (other.remark != null)
				return false;
		} else if (!remark.equals(other.remark))
			return false;
		if (startTime == null) {
			if (other.startTime != null)
				return false;
		} else if (!startTime.equals(other.startTime))
			return false;
		return true;
	}

	
}
